package com.tskj.leonsu.service;

import com.alibaba.fastjson.JSONArray;
import com.tskj.leonsu.dao.BadmintonDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author LeonSu
 */
@Service
public class BadmintonService implements OrderServiceBiz {

    @Autowired
    private BadmintonDAO badmintonDAO;

    @Override
    public JSONArray getUnFinishedOrder(String adUserName) {
        return badmintonDAO.getUnFinishedOrder(adUserName);
    }

    @Override
    public JSONArray getFinishedOrder(String adUserName) {
        return badmintonDAO.getFinishedOrder(adUserName);
    }

    @Override
    public JSONArray getAllOrder(String adUserName) {
        return badmintonDAO.getAllOrder(adUserName);
    }

    @Override
    public void confirmOrder(String adUserName, String orderId) throws Exception {
        if (badmintonDAO.getCanConfirm(orderId)) {
            badmintonDAO.confirmOrder(adUserName, orderId);
        } else {
            throw new Exception("订单确认失败，未到允许订单确认时间");
        }
    }

    @Override
    public void cancelOrder(String adUserName, String orderId) throws Exception {
        if (badmintonDAO.getCanCancel(orderId)) {
            badmintonDAO.cancelOrder(adUserName, orderId);
        } else {
            throw new Exception("订单取消失败，超过订单取消时间");
        }
    }
}
